/**
 * 评估所需信息
 */
/* eslint-disable no-shadow */

const state = {
  drugs: [], // 用药记录列表(记录在这里是为了选择药品时为了排重)
  planDrugs: [], // 待开方药品列表
  doctorId: '', // 医生ID
  diseaseIds: [], // 疾病id数组
  estimatedPickupPeriod: 2, // 预约取药周期
  // estimatedPickupDay: '2021-01-01', // 预约取药时间
  estimatedPickupDay: {
    initTime: '',
    setTime: ''
  }, // 预约取药时间
  addressInfo: {
    name: '',
    machineNumber: '',
    address: {
      provinceId: '',
      provinceName: '',
      cityId: '',
      cityName: '',
      areaId: '',
      areaName: ''
    },
    street: '',
    state: 0
  },

  scanDrugs: [] // 图像搜索结果
};

const mutations = {
  SET_DRUGS: (state, item) => {
    state.drugs = state.drugs.concat(item);
  },
  DEL_DRUGS: (state, index) => {
    state.drugs.splice(index, 1);
  },
  PUT_DRUGS: (state, data) => {
    Object.assign(state.drugs[data.index], data.item);
  },
  DEL_ALL_DRUGS: (state, data) => {
    state.drugs = [];
  },

  SET_PERIOD: (state, num) => {
    state.estimatedPickupPeriod = num;
  },
  SET_DAY: (state, time) => {
    state.estimatedPickupDay = { ...state.estimatedPickupDay, ...time };
  },
  SET_ADDRESS: (state, address) => {
    state.addressInfo = address;
  },
  SET_DISEASE: (state, item) => {
    state.diseaseIds = item;
  },
  SET_DOCTOR: (state, id) => {
    state.doctorId = id;
  },
  SET_PLAN_DRUGS: (state, item) => {
    state.planDrugs = item || [];
  },
  SET_SCAN_DRUGS: (state, item) => {
    state.scanDrugs = item;
  },
  DEL_SCAN_DRUGS: (state) => {
    state.scanDrugs = [];
  }
};

const actions = {};

export default {
  namespaced: true,
  state,
  mutations,
  actions
};
